<template>
    <div>

        <!-- <nav>
            <router-link to="/orders">订单页</router-link>
        </nav> -->

        <el-table :cell-style="{ textAlign: 'center',color:'black' }" :header-cell-style="{ 'text-align': 'center',color:'black' }"
            :data="goodsList" style="">
            <el-table-column prop="name" label="套餐名" />
            <el-table-column prop="description" label="描述" />
            <el-table-column prop="price" label="价格(元)" />
            <el-table-column label="操作">
                <template v-slot="scope">
                    <el-button type="primary" @click="buy(scope.row)">购买</el-button>
                </template>

            </el-table-column>
        </el-table>

    </div>
</template>

<script>
import { list, buy } from '@/api/goods'
export default {
    data() {
        return {
            goodsList: []
        }
    },


    mounted() {
        this.laodData()
    },
    activated() {
        this.laodData()
    },

    methods: {
        laodData() {
            list().then(res => {
                this.goodsList = res.data
            })
        },
        buy(row) {
            console.log(row)

            buy(row.id).then(res => {

                if (res.code == 1) {
                    this.$message.success("订单生成成功,即将跳转至支付页面")
                    //跳转
                    setTimeout(() => {
                        // var url = 'http://7ac071bc.r27.cpolar.top'
                        var url = 'http://127.0.0.1:1145'
                        window.location.href = url + '/alipay/pay?orderId=' + res.data.orderId
                    }, 1000);
                    // window.open('http://119.29.202.127:8080/ai/alipay/pay?orderId=' + res.data.orderId)
                } else {
                    this.$message.error("下单失败")
                }
            })


        }
    },

}
</script>

<style></style>